import 'package:enterprise_v6_app/app/components/custom_modele/custom_card.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_dropdown_selection.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/file_util.dart';
import 'package:enterprise_v6_app/app/data/entities/application/standardiztion/standard_scence_safe_appliance_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/standardiztion/standard_scence_safe_third_assess_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/standardiztion/standard_scence_safe_third_continue_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/standardiztion/standard_scence_safe_third_inspect_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/standardiztion/standard_scence_safe_third_work_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/standardiztion/standardization_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/standardization/common.dart';
import 'package:enterprise_v6_app/app/modules/application/standardization/pages/scence/work_safe/ctrl.dart';
import 'package:enterprise_v6_app/app/modules/application/standardization/pages/scence/work_safe/model.dart';

/// 作业安全
class StandardizationScenceSafeView extends StatelessWidget {
  StandardizationScenceSafeView({super.key});

  final ctrl = Get.put(StandardizationScenceSafeController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: ctrl,
      builder: (_) {
        return Column(
          children: [
            CustomDropdownSelection(
              text: ctrl.type.name,
              onCallBack: ctrl.showSelect,
              height: 37.w,
            ),
            AppGaps.vGap10,
            Expanded(child: _buildBody()),
          ],
        );
      },
    );
  }

  Widget _buildBody() {
    if (ctrl.type == StandardizationSafeMenuType.labor) {
      return CustomEasyRefreshList<StandardScenceSafeApplianceEntity>(
        key: ValueKey(ctrl.type),
        isShowSearch: true,
        dataLoad: ctrl.getLaobao,
        itemBuilder: (entity, _) {
          return CustomCard(
            title: entity.workProjectName,
            titleRight: SvgPicture.asset(AppImages.icon_job_right),
            divider: CustomCard.builtinDividerWithPadding,
            content: Column(
              children: [
                StandardizationCommon.buildItem('所属部门', entity.departmentIdName),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('创建时间', entity.createDate),
                AppGaps.vGap6,
                StandardizationCommon.buildItem('发放日期', entity.dueDate),
              ],
            ),
          );
        },
      );
    } else if (ctrl.type == StandardizationSafeMenuType.qualificationReviewRecords) {
      return CustomEasyRefreshList<StandardScenceSafeThirdInspectEntity>(
        key: ValueKey(ctrl.type),
        isShowSearch: true,
        dataLoad: ctrl.getShenCha,
        itemBuilder: (entity, _) {
          return CustomCard(
            title: entity.name,
            onTap: () => FileUtils.openFile(entity.fileAddressUrl),
            divider: CustomCard.builtinDividerWithPadding,
            titleRight: SvgPicture.asset(AppImages.icon_job_right),
            content: Column(
              children: [
                StandardizationCommon.buildItem('创建时间', entity.createDate),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('第三方单位', entity.thirdPartName),
                AppGaps.vGap6,
                StandardizationCommon.buildItem2('审查结果', entity.reviewResult),
              ],
            ),
          );
        },
      );
    } else if (ctrl.type == StandardizationSafeMenuType.thirdJobProcessInspection) {
      return CustomEasyRefreshList<StandardScenceSafeThirdWorkEntity>(
        key: ValueKey(ctrl.type),
        isShowSearch: true,
        dataLoad: ctrl.getProcess,
        itemBuilder: (entity, _) {
          return CustomCard(
            title: entity.thirdPartName,
            divider: CustomCard.builtinDividerWithPadding,
            titleRight: SvgPicture.asset(AppImages.icon_job_right),
            onTap: () => FileUtils.openFile(entity.fileAddressUrl),
            content: Column(
              children: [
                StandardizationCommon.buildItem('检查日期', entity.createDate),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('作业时间', '${entity.workTimeBegin}\n${entity.workTimeEnd}'),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('作业地点', entity.workPoint),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('区域负责人', entity.workAreaPerson),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('负责人联系方式', entity.phone),
              ],
            ),
          );
        },
      );
    } else if (ctrl.type == StandardizationSafeMenuType.thirdPerformanceEvaluation) {
      return CustomEasyRefreshList<StandardScenceSafeThirdAssessEntity>(
        key: ValueKey(ctrl.type),
        isShowSearch: true,
        dataLoad: ctrl.getAssess,
        itemBuilder: (entity, _) {
          return CustomCard(
            title: entity.name,
            divider: CustomCard.builtinDividerWithPadding,
            titleRight: SvgPicture.asset(AppImages.icon_job_right),
            onTap: () => FileUtils.openFile(entity.fileAddressUrl),
            content: Column(
              children: [
                StandardizationCommon.buildItem('第三方单位', entity.thirdPartName),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('评价日期', entity.evaluateDate),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('评价人', entity.evaluatePerson),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('评价结论', entity.checkPerson),
              ],
            ),
          );
        },
      );
    } else if (ctrl.type == StandardizationSafeMenuType.thirdContinuationExitRecord) {
      return CustomEasyRefreshList<StandardScenceSafeThirdContinueEntity>(
        key: ValueKey(ctrl.type),
        isShowSearch: true,
        dataLoad: ctrl.getContinue,
        itemBuilder: (entity, _) {
          return CustomCard(
            title: entity.name,
            divider: CustomCard.builtinDividerWithPadding,
            titleRight: SvgPicture.asset(AppImages.icon_job_right),
            onTap: () => FileUtils.openFile(entity.fileAddressUrl),
            content: Column(
              children: [
                StandardizationCommon.buildItem('第三方单位', entity.thirdPartName),
                AppGaps.vGap10,
                StandardizationCommon.buildItem('类型', entity.type == 1 ? '续用' : '退出'),
              ],
            ),
          );
        },
      );
    }
    return CustomEasyRefreshList<StandardizationEntity>(
      key: ValueKey(ctrl.type),
      isShowSearch: true,
      dataLoad: ctrl.getPages,
      itemBuilder: StandardizationCommon.card,
    );
  }
}
